package com.bdqn.oa.dao.impl;

import com.bdqn.oa.dao.ReportCommentDao;
import com.bdqn.oa.entity.ReportComment;
import com.bdqn.oa.utils.DateUtils;
import com.bdqn.oa.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author Zhouxw
 * @date 2022/7/21 20:49
 */
public class ReportCommentDaoImpl implements ReportCommentDao {
    QueryRunner queryRunner = new QueryRunner();

    /**
     * 新增一条工作汇报点评
     *
     * @param reportComment 工作汇报点评
     * @return 影响行数
     */
    @Override
    public int saveReportComment(ReportComment reportComment) throws SQLException {
        String sql = "insert into report_comment (datetime, content, rating, `name`) value (?, ?, ?, ?)";
        int result = queryRunner.update(DruidUtils.getConnection(), sql, reportComment.getDatetime(), reportComment.getContent(),
                reportComment.getRating(), reportComment.getName());
        return result;
    }

    /**
     * 通过id查询工作汇报点评
     *
     * @param id 工作汇报点评id
     * @return 工作汇报点评
     */
    @Override
    public ReportComment getReportCommentById(Integer id) throws SQLException {
        String sql = "select * from report_comment where id = ?";
        ReportComment reportComment = queryRunner.query(DruidUtils.getConnection(), sql, new BeanHandler<>(ReportComment.class), id);
        return reportComment;
    }
}
